package com.kettle;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

/**
 * @ClassName Test
 * @Author YanZhen
 * @Date 2021/6/17
 * @Version V1.0
 **/
public class Test {

    public static void main(String[] args) throws KettleException {
        runJob();
        runTransfer();
    }


    public static void runTransfer()throws KettleException{
        KettleEnvironment.init();
        TransMeta tm = new TransMeta("/Users/scott/Documents/Db-user-transfer.ktr");
        Trans trans = new Trans(tm);
        trans.execute(null);
        trans.waitUntilFinished();
    }

    public static void runJob() throws KettleException {
        KettleEnvironment.init();
        // 任务元对象  fileName为作业的绝对路径C:\Users\Administrator\Desktop\参数传递测试作业.kjb

        JobMeta jm = new JobMeta("/Users/scott/Documents/db-user-transfer-zuo.kjb", null);
        // 任务
        Job job = new Job(null, jm);
        // 传参
      /*  job.setVariable("beginTime", beginTime);
        job.setVariable("endTime", endTime);*/
        // 开始任务
        job.start();
        // 等待任务结束
        job.waitUntilFinished();
    }
}
